<template>
  <div class="alert">
    <div class="alert-content" :key="item.name" v-for="item in list">
      {{item.txt}}
    </div>
  </div>
</template>
<script>
  let uuid = 0
  function getUuid() {
    return ++uuid
  }
  export default {
    name: 'Alert',
    data() {
      return {
        list: []
      }
    },
    methods: {
      showTxt(txt) {
        const uuid = getUuid()
        this.list.push({
          name: uuid,
          txt: txt
        })

        setTimeout(() => {
          const index = this.list.findIndex(item => item.name === uuid)
          this.list.splice(index, 1)
        }, 2300)
      }
    }
  }
</script>
<style scoped rel="stylesheet/stylus">
  .alert {
    position: fixed;
    width: 100%;
    top: 18px;
    left: 0;
    right: 0;
    text-align: center;
  }

  .alert-content {
    display: inline-block;
    padding: 8px 16px;
    background: #fff;
    border-radius: 3px;
    box-shadow: 0 1px 6px rgba(0, 0, 0, .2);
    margin-bottom: 8px;
  }

</style>
